# -*- Python -*-

import os
import platform
import re
import subprocess
import site
from math import log

try:
    import lit.formats
    import lit.util
except ImportError:
    pass

site.addsitedir(config.module_dir)
import dynamic_test

# Configuration file for the 'lit' test runner.

# name: The name of this test suite.
config.name = 'Covert C++ Dynamic Noninterference'

# Tweak PATH for Win32
if platform.system() == 'Windows':
    # Seek sane tools in directories and set to $PATH.
    path = getattr(config, 'lit_tools_dir', None)
    path = lit_config.getToolsPath(path,
                                   config.environment['PATH'],
                                   ['cmp.exe', 'grep.exe', 'sed.exe'])
    if path is not None:
        path = os.path.pathsep.join((path,
                                     config.environment['PATH']))
        config.environment['PATH'] = path

config.test_format = dynamic_test.DynamicTest()

# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.c', '.cpp']

# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)

# process lit.site.cfg
NVT = getattr(config, 'NVT', None)
if not NVT:
    lit_config.fatal("\'NVT\' undefined")
drrun = getattr(config, 'drrun', None)
if not drrun:
    lit_config.fatal("\'drrun\' undefined")

# Tweak the PATH to include the tools dir.
covert_tools_dir = getattr(config, 'covert_tools_dir', None)
if not covert_tools_dir:
    lit_config.fatal('No Covert C++ tools dir found!')
path = os.path.pathsep.join((covert_tools_dir, config.environment['PATH']))
config.environment['PATH'] = path

# Check that the object root is known.
test_exec_root = getattr(config, 'test_exec_root', None)
if not test_exec_root:
    lit.fatal('test execution root not set!')

config.substitutions.append( ('%nvt', ' ' + drrun + ' -c ' + NVT + ' -b -c ' + str(config.memory_mask_bits) + ' ') )
config.substitutions.append( ('%r', test_exec_root) )
